import logging

from fastapi import FastAPI

from src.routers import chat, upload

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    datefmt="%Y-%m-%d %H:%M:%S",
)
logger = logging.getLogger(__name__)

app = FastAPI(title="YuanBao API Proxy", version="1.0.0")

app.include_router(chat.router)
app.include_router(upload.router)

if __name__ == "__main__":
    import uvicorn
    
    # 配置服务器超时设置
    config = uvicorn.Config(
        "app:app",
        host="0.0.0.0",
        port=8000,
        reload=True,
        timeout_keep_alive=300,  # 保持连接超时时间（秒）
        timeout_notify=300,      # 通知超时时间（秒）
        timeout_graceful_shutdown=10,  # 优雅关闭超时时间（秒）
        limit_concurrency=100,  # 并发连接数限制
    )
    server = uvicorn.Server(config)
    server.run()
